import { getApi, postApi, service } from "../../config/request";
import { AxiosPromise } from "axios";

import {
  AddDevice,
  DeviceConfig,
  SearchDeviceList,
  DeviceInfo,
  AllDeviceList,
  UserDeviceBinding,
  RelationList,
  SearchLedgerList,
  KeepLedger,
  LedgerDetail,
  ExportResParmas,
  CreateModifyPlan,
  WarningType,
} from "./type";

// 设备列表
export const reqDeviceList = (
  params: SearchDeviceList
): AxiosPromise<DeviceInfo> => {
  return postApi("/fridge_business/platform/device/page", params);
};

// 新增设备
export const reqAddDevice = (params: AddDevice): AxiosPromise => {
  return postApi("/fridge_business/platform/device/add", params);
};

/**
 * /获取设备配置
 * @param machineCode  设备编码
 * @returns
 */
export function reqDeviceCofing(params: {
  machineCode: string;
}): AxiosPromise<DeviceConfig> {
  return getApi("/fridge_business/platform/device/get_config", {
    params,
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
  });
}

// 单位所有设备
export function reqUnitAllDevice(
  params: object = {}
): AxiosPromise<AllDeviceList[]> {
  return getApi("/fridge_business/platform/device/unit/all", {
    params,
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
  });
}

// 设置设备参数
export const reqSetConfig = (params: DeviceConfig): AxiosPromise => {
  return postApi("/fridge_business/platform/device/set_config", params);
};

// 设备-用户绑定关系列表
export function reqDeviceUserList(params: {
  machineCode: string;
}): AxiosPromise<RelationList> {
  return getApi("/fridge_business/platform/user_device/user_list", {
    params,
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
  });
}

// 设备-用户绑定&解绑关系
export const reqBindUser = (params: UserDeviceBinding): AxiosPromise => {
  return postApi("/fridge_business/platform/user_device/binding_user", params);
};

// 用户已绑定关系列表
export function reqBindDeviceList(
  params: object = {}
): AxiosPromise<AllDeviceList> {
  return getApi("/fridge_business/platform/user_device/list", {
    params,
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
  });
}

// 留样计划列表
export const reqKeepPlanList = (params: object = {}): AxiosPromise => {
  return postApi(
    "/fridge_business/platform/fridge/keep_count/page_plan",
    params
  );
};

// 留样台账列表
export const reqKeepLedgerList = (
  params: SearchLedgerList
): AxiosPromise<KeepLedger> => {
  return postApi(
    "/fridge_business/platform/fridge/keep_count/query_page",
    params
  );
};

/**
 *
 * @param keepCountId
 * @returns
 */
// 留样台账-详情
export function reqLedgerDetail(params: {
  keepCountId: string;
}): AxiosPromise<LedgerDetail> {
  return getApi("/fridge_business/platform/fridge/keep_count/detail", {
    params,
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
  });
}

// 留样计划-创建留样计划
export const reqCreatePlan = (
  params: object = {}
): AxiosPromise<CreateModifyPlan> => {
  return postApi(
    "/fridge_business/platform/fridge/keep_count/plan_keep",
    params
  );
};

// 留样计划-删除
export const reqDeletePlan = (params: { id: string }): AxiosPromise => {
  return postApi(
    "/fridge_business/platform/fridge/keep_count/plan_delete",
    params,
    {
      "Content-Type": "application/x-www-form-urlencoded",
    }
  );
};

// 留样台账-导出
export function reqExportLedge(params: ExportResParmas): AxiosPromise {
  return getApi(
    "/fridge_business/platform/fridge/keep_count/export_keep_count",
    {
      params,
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
      responseType: "blob",
    }
  );
}

// 预警管理-预警消息列表
export const reqWarningList = (params: {}): AxiosPromise => {
  return postApi("/fridge_business/platform/fridge/warning/page", params);
};

// 预警管理-预警类型
export function reqWarnType(params: object = {}): AxiosPromise<WarningType> {
  return getApi("/fridge_business/wx/fridge/warning/type/list", {
    params,
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
  });
}

// 预警管理-预警信息导出
export const exportWarningInfo = (params: {}): AxiosPromise => {
  return postApi(
    "/fridge_business/platform/fridge/warning/export_warning",
    params,
    { responseType: "blob" }
  );
};
